<?php
/**
 *
 *
 * @author camfee <camfee@foxmail.com>
 * @date   17-9-5 上午9:23
 *
 */
require_once('../../common.inc.php');

class gs extends lib\core\Action
{
    public function doDefault()
    {
        $smarty = $this->app->page();
        $aid = intval($_GET['id']);
        $userid = intval($_GET['uid']);
        $ars = \Center\Active::getInfoByIds($aid);
        $aors = \Center\ActiveOffer::getListByActId($aid, 9999, true);
        $myoffer = \Center\ActiveOffer::getMyActivesOffers([$aid], $userid)['offers'][$aid];
        $bouns = $uid = $all = [];
        $i = 0;
        $cnt = count($aors);
        foreach ($aors as $val) {
            if ($val['Status'] == 1) {
                $uid[] = $val['UserId'];
                $bouns = [
                    'UserId' => $val['UserId'],
                    'Status' => $val['Status'],
                    'OfferPrice' => $val['OfferPrice'],
                    'CreateTime' => $val['CreateTime'],
                ];
                if ($cnt > 20) {
                    $i = 1;
                    $tmp = $all;
                    $all = [];
                }
                $all[] = $bouns;
            } elseif ($i < 20) {
                $uid[] = $val['UserId'];
                $all[] = [
                    'UserId' => $val['UserId'],
                    'Status' => $val['Status'],
                    'OfferPrice' => $val['OfferPrice'],
                    'CreateTime' => $val['CreateTime'],
                ];
                if ($i > 0) {
                    $i ++;
                }
            }
        }
        krsort($all);
        if (count($all) < 20) {
            krsort($tmp);
            foreach ($tmp as $v) {
                if (count($all) < 20) {
                    $all[] = $v;
                } else {
                    break;
                }
            }
        }
        $uid[] = $userid;
        $uid_arr = \Center\User::getInfoByIds($uid);
        $data = [
            'Name' => $ars['Name'],
            'CreateTime' => $ars['CreateTime'],
        ];
        $smarty->value('data', $data);
        $smarty->value('userid', $userid);
        $smarty->value('bouns', $bouns);
        $smarty->value('all', $all);
        $smarty->value('myoffer', $myoffer);
        $smarty->value('user', $uid_arr);
        $smarty->output();
    }
}
$app->run();